package pers.lan.hash;

import java.util.HashSet;
import java.util.Set;

/**
 * @author <p><a href="mailto:1728209643@qq.com">XiaoSan</a>
 * @date 2019/11/25 8:51 AM
 */
public class LC_36 {

    public boolean isValidSudoku(char[][] board) {
        Set<Character>[] sets = new Set[9];
        Set<Character> set = new HashSet<>();
        for (int i = 0; i < board.length; i++) {
            set.clear();
            for (int i1 = 0; i1 < board[0].length; i1++) {
                if (board[i][0] != '.' && !set.add(board[i][0])) {
                    return false;
                }
                if (sets[i1] == null) {
                    sets[i1] = new HashSet<>();
                }
                if (board[i][0] != '.' && !sets[i1].add(board[i][0])) {
                    return false;
                }
            }
        }
        return true;
    }
}
